home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16440 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  69 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!marnold
  3. From: marnold@netcom.com (Matt Arnold)
  4. Subject: Re: The STL and nested structures
  5. Message-ID: <marnoldDpn0HH.3z2@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <4ju9q7$fa1$1@mhadg.production.compuserve.com> <316a26d7.2989288@news.cyberport.com>
  8. Date: Wed, 10 Apr 1996 08:20:04 GMT
  9. Sender: marnold@netcom23.netcom.com
  10.  
  11. tangent@cyberport.com (Warren Young) writes:
  12.  
  13. >Alan Huff <74312.2300@CompuServe.COM> wrote:
  14.  
  15. >>I am having a problem using the STL with structures defined within 
  16. >>a class definition.  Consider the following code fragment.
  17. >>
  18. >>>#include <vector.h>
  19. >>>class Bar {
  20. >>>   struct Foo {
  21. >>>      int   value;
  22. >>>   };
  23. >>>
  24. >>>   vector< Foo > fooContainer;
  25. >>>}
  26. >>
  27. >>The compiler I am using (VC 4.1) refuses to compile.  An error is 
  28. >>generated the says "'Foo' : undeclared identifier" at line 75 in 
  29. >>vector.h.
  30.  
  31. >It _is_ undeclared, just as a variable local to a function foo() is
  32. >undeclared in a function bar().  What you want to say is:
  33.  
  34. >vector<Bar::Foo> fooContainer;
  35.  
  36. This should not be necessary.  Nested class Foo should be visible for
  37. use in template member Bar::fooContainer.  fooContainer is in Bar's
  38. scope.  There should be no problem referring to it within Bar.  
  39.  
  40. I think Visual C++ is broken on the above code.  It compiles fine in 
  41. Borland C++.
  42.  
  43. Your above function scope anology doesn't apply here.  Foo is already 
  44. being used in the correct scope.
  45.  
  46. >Even this won't work until Foo is placed in the public section of the
  47. >class (as shown above, it's in the private (default) section).
  48.  
  49. That requirement would make private nested implementation class'
  50. impossible, wouldn't it?
  51.  
  52. STL, for example, uses this exact construct.  Nested structs and 
  53. classes in private and protected sections of the nesting class that 
  54. are passed on---unqualified---as parameters to templated members of 
  55. the nesting class (see the rb_tree_node nested struct in the rb_tree 
  56. class, found in "tree.h").
  57.  
  58. Is it true that STL is currently incorrectly implemented?
  59.  
  60. Regards,
  61. -------------------------------------------------------------------------
  62. Matt Arnold                       |        | ||| | |||| |  | | || ||
  63. marnold@netcom.com                |        | ||| | |||| |  | | || ||
  64. Boston, MA                        |      0 | ||| | |||| |  | | || ||
  65. 617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
  66. C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
  67. -------------------------------------------------------------------------
  68.  
  69.